﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using ArchiSimple.Windows.ViewModel.PlanObjects;
#if NETFX_CORE
using Windows.UI.Xaml.Controls;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Data;
#else
using System.Windows.Controls;
using System.Windows.Data;
#endif

namespace ArchiSimple.Windows
{
    public class PlanObjectPanel : Canvas
    {
        protected override Size ArrangeOverride(Size finalSize)
        {
            foreach (var item in this.Children)
            {
                var element = item as FrameworkElement;

                var planobject = element.DataContext as PlanObjectViewModel;

                if (planobject != null)
                {
                    if (planobject.Zone != null)
                    {
                        Binding bindingX = new Binding();
                        bindingX.Path = new PropertyPath("Zone.X");
                        bindingX.Source = planobject;
                        BindingOperations.SetBinding(element, Canvas.LeftProperty, bindingX);

                        Binding bindingY = new Binding();
                        bindingY.Path = new PropertyPath("Zone.Y");
                        bindingY.Source = planobject;
                        BindingOperations.SetBinding(element, Canvas.TopProperty, bindingY);
                    }
                }
            }

            return base.ArrangeOverride(finalSize);
        }
    }
}
